package com.magicborrow.adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.magicborrow.Constants;
import com.magicborrow.R;
import com.magicborrow.activity.BorrowStuffDetailActivity;
import com.magicborrow.beans.WaresListBean;
import com.magicborrow.enums.PriceModeEnum;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

import java.util.ArrayList;

/**
 * Created by ghost on 16/5/26.
 */
public class CanBorrowingAdapter extends RefreshAdapter<WaresListBean.DataEntity.CanBorrowingBean> {
    private DisplayImageOptions options;

    public CanBorrowingAdapter(ArrayList<WaresListBean.DataEntity.CanBorrowingBean> data) {
        super(data);
    }

    @Override
    public RecyclerView.ViewHolder onCreateItem(ViewGroup parent, int viewType) {
        return new CanBorrowingViewHolder(LayoutInflater.from(context).inflate(R.layout.can_borrowing_item, null));
    }

    @Override
    public void onBindItem(RecyclerView.ViewHolder holder, final int position) {
        CanBorrowingViewHolder cHolder = (CanBorrowingViewHolder) holder;
        cHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, BorrowStuffDetailActivity.class);
                intent.putExtra("data",data.get(position).getWareVO());
                context.startActivity(intent);
            }
        });
        if (position == data.size()) {
            cHolder.vBottom.setVisibility(View.VISIBLE);
        } else {
            cHolder.vBottom.setVisibility(View.GONE);
        }
        if (options == null)
            options = new DisplayImageOptions.Builder().displayer(new RoundedBitmapDisplayer(context.getResources().getDimensionPixelOffset(R.dimen._30dp))).build();

     /*   ImageLoader.getInstance().displayImage(Constants.ADDRESS + data.get(position).getWareVO().getUser().getAvatar80(),
                cHolder.imvHeader, options);*/
        cHolder.tvName.setText(data.get(position).getWareVO().getUser().getNickname());
        cHolder.tvStuffName.setText(data.get(position).getWareVO().getName());
        cHolder.tvPrice.setText("￥" + data.get(position).getWareVO().getPrice() + "/" + PriceModeEnum.getModeStr(data.get(position).getWareVO().getPriceMode()));

    }

    public class CanBorrowingViewHolder extends RecyclerView.ViewHolder {
        private ImageView imvHeader;
        private TextView tvName;
        private TextView tvStuffName;
        private TextView tvPrice;
        private View vBottom;

        public CanBorrowingViewHolder(View view) {
            super(view);
            imvHeader = (ImageView) view.findViewById(R.id.imv_header);
            tvName = (TextView) view.findViewById(R.id.tv_name);
            tvStuffName = (TextView) view.findViewById(R.id.tv_stuff_name);
            tvPrice = (TextView) view.findViewById(R.id.tv_price);
            vBottom = (View) view.findViewById(R.id.v_bottom);
        }
    }
}
